<%@page import="study.itwill.team5.admin.AdminItem"%>
<%@page import="study.itwill.jsp.WebHandler"%>
<%@page import="study.itwill.team5.admin.Admin"%>
<%@page import="study.itwill.common.PatternChecker"%>
<%@page import="study.itwill.common.DBHandler"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ include file="../session.jsp"%>
<%@ include file="../dbcon.jsp"%>
<%
	PatternChecker checker = PatternChecker.getInstance();
	
	// 모든 파라미터 받기
	int seq = web.getInt("seq");
	String admin_id = web.getValue("admin_id");
	String admin_pw = web.getValue("admin_pw");
	int admin_level = web.getInt("admin_level");
	String admin_comment = web.getValue("admin_comment");
	
	if (seq == -1) {
		db.disconnect();
		web.goPage(null, "파라미터가 잘못되었습니다.");
		return;
	}
	
	if (!checker.isValue(admin_pw) || !checker.isEngNum(admin_pw)) {
		db.disconnect();
		web.goPage(null, "파라미터가 잘못되었습니다.");
		return;
	}
	
	if (admin_level == -1) {
		db.disconnect();
		web.goPage(null, "파라미터가 잘못되었습니다.");
		return;
	}
	
	if (!checker.isValue(admin_comment)) {
		db.disconnect();
		web.goPage(null, "파라미터가 잘못되었습니다.");
		return;
	}
%>
<%
	/** 데이터 저장 */
	Admin admin = new Admin();
	boolean result = admin.editAdmin(seq, admin_id, admin_pw, admin_level, admin_comment);
	
	/** 접속 해제 */
	db.disconnect();
	
	if (!result) {
		web.goPage(null, "수정에 실패했습니다.");
		return;
	}
	
	// 페이지 강제 이동 (JSP)
	web.goPage("viewAdmin.jsp?seq=" + seq, null);
%>